using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NTTHAO.Web.BL.Rss;

public partial class admin_webparts_Plug_ins_RssNews_RssSources : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string site = Request.QueryString["site"];
            string action = Request.QueryString["action"];
            string controlName = string.Empty;

            if ("addsite".Equals(action, StringComparison.OrdinalIgnoreCase))
            {
                controlName = "RssSiteInput.ascx";
            }
            else if ("editsite".Equals(action, StringComparison.OrdinalIgnoreCase))
            {
                controlName = "RssSiteInput.ascx";
            }
            else if ("removesite".Equals(action, StringComparison.OrdinalIgnoreCase))
            {
            }
            else if ("addlink".Equals(action, StringComparison.OrdinalIgnoreCase))
            {
                controlName = "RssLinkInput.ascx";
            }
            else if ("editlink".Equals(action, StringComparison.OrdinalIgnoreCase))
            {
                controlName = "RssLinkInput.ascx";
            }
            else if ("removelink".Equals(action, StringComparison.OrdinalIgnoreCase))
            {
                if (Request.QueryString["id"] != null)
                {
                    this.RemoveLink(Request.QueryString["id"].Trim());
                }

                string bUrl = "?type=" + Request.QueryString["type"] + "&name=" + Request.QueryString["name"] + "&item=" + Request.QueryString["item"] + (Request.QueryString["site"] == null ? "" : "&site=" + Request.QueryString["site"]);
                Response.Redirect(bUrl, false);
                return;
            }

            if (controlName == string.Empty)
            {
                controlName = "RssSourcesLinks.ascx";
            }

            Control ctrl = this.LoadControl(controlName);
            this.contentCont.Controls.Add(ctrl);
        }
        catch (Exception ex)
        {
            HtmlGenericControl ctrl = new HtmlGenericControl("div");
            ctrl.InnerHtml = "<p>" + ex.Message + "</p><p>" + ex.StackTrace + "</p>";
            this.contentCont.Controls.Add(ctrl);
        }
    }

    public void RemoveLink(string idStr)
    {
        try
        {
            int id = Convert.ToInt32(idStr);

            RssLink link = new RssLink(id);
            if (link.ID > 0)
            {
                link.Delete();
            }
        }
        catch { }
    }
}
